<extend name="common/layouts"/>


<block name="content">

    <div class="kt-portlet">
        <div class="kt-portlet__head">
            <div class="kt-portlet__head-label">
                <h3 class="kt-portlet__head-title">
                    课程一览
                </h3>
            </div>
        </div>
        <div class="kt-portlet__body">

            <!--begin::Section-->
            <div class="kt-section">
                <div class="kt-section__content">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>课程名称</th>
                            <th>教师</th>
                            <th>上课时间</th>
                            <th>上课地点</th>
                            <th>学分</th>
                            <th>课时</th>
                            <th>最多人数</th>
                            <td>已报名</td>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <foreach name="list" item="vo">
                            <tr>
                                <th>{$vo['id']}</th>
                                <th scope="row">{$vo['name']}</th>
                                <th scope="row">{$vo['teacher']}</th>
                                <td>{$vo['time']}</td>
                                <td>{$vo['address']}</td>
                                <td>{$vo['score']}</td>
                                <td>{$vo['class_hour']}</td>
                                <td>{$vo['limit']}</td>
                                <td>{$vo['already']}</td>
                                <td>
                                    <a class="btn btn-success btn-sm" onclick="confirmSelect({$vo['id']})">选择此课程</a>
                                </td>
                            </tr>
                        </foreach>

                        </tbody>

                    </table>
                </div>
            </div>

            <div class="ck-paginate font-weight-bold kt-font-lg kt-font-regular">
                {$page}
            </div>
            <!--end::Section-->


        </div>

        <!--end::Form-->
    </div>
</block>

<block name="js">
    <script>
        var confirmSelect = function (id) {

            var flag = window.confirm('确认选择本课程？');
            if (flag) {
                $.ajax({
                    url: '/home/choose/store',
                    data: {
                        class_id: id
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 0) {
                            toastr.success("选课成功");
                            setTimeout(function () {
                                window.history.go(-1);
                            }, 1500);
                        } else {
                            toastr.error(result.msg);
                            return;
                        }
                    }
                })
            }
        }
    </script>
</block>